import request from '@/config/axios'

// OA 请假申请 VO
export interface LeaveApplyVO {
  id: number // 请假表单主键
  userId: number // 申请人的用户编号
  type: number // 请假类型
  reason: string // 请假原因
  startTime: Date // 开始时间
  startType: number // 开始时间类型1.上午 2.下午
  endTime: Date // 结束时间
  endType: number // 结束时间类型1.上午 2.下午
  day: number // 请假天数
  hours: number // 加班小时数
  status: number // 审批结果
  processInstanceId: string // 流程实例的编号
  createTime: Date // 创建时间
  updateTime: Date // 更新时间
  creator: string // 创建者
  createName: string // 创建者姓名
  updater: string // 更新者
  updateName: string // 更新者姓名
}

// 请假时长计算请求VO
export interface LeaveDurationCalcReqVO {
  startTime: string
  startType: number
  endTime: string
  endType: number
}

// 请假时长计算响应VO
export interface LeaveDurationCalcRespVO {
  day: number
  hours: number
}

// OA 请假申请 API
export const LeaveApplyApi = {
  // 查询OA 请假申请分页
  getLeaveApplyPage: async (params: any) => {
    return await request.get({ url: `/oa/leave-apply/page`, params })
  },

  // 查询OA 请假申请详情
  getLeaveApply: async (id: number) => {
    return await request.get({ url: `/oa/leave-apply/get?id=` + id })
  },

  // 新增OA 请假申请
  createLeaveApply: async (data: LeaveApplyVO) => {
    return await request.post({ url: `/oa/leave-apply/create`, data })
  },

  // 修改OA 请假申请
  updateLeaveApply: async (data: LeaveApplyVO) => {
    return await request.put({ url: `/oa/leave-apply/update`, data })
  },

  // 删除OA 请假申请
  deleteLeaveApply: async (id: number) => {
    return await request.delete({ url: `/oa/leave-apply/delete?id=` + id })
  },

  // 导出OA 请假申请 Excel
  exportLeaveApply: async (params) => {
    return await request.download({ url: `/oa/leave-apply/export-excel`, params })
  },

  // 统计指定用户本年度每月审核通过的请假申请数量
  getMonthlyApprovedCountByUser: async (userId: number, year: number) => {
    return await request.get({ url: `/oa/leave-apply/monthly-statistics`, params: { userId, year } })
  },

  // 计算请假时长
  calculateLeaveDuration: async (params: LeaveDurationCalcReqVO): Promise<LeaveDurationCalcRespVO> => {
    return await request.get({ url: `/oa/leave-apply/calculate-leave-duration`, params })
  },

  // 取消假期
  cancelLeave: async (id: number, reason: string) => {
    return await request.post({ url: `/oa/leave-apply/cancel`, data: { id, reason } })
  },
}
